<template>
    <div class="FooterMusic">
        <div class="footLeft">
            <img :src="playList[playListIndex].al.picUrl" alt="">
            <div class="songDetail">
                <p>{{playList[playListIndex].name}}</p>
                <span>横滑可以切换上下首哦</span>
            </div>
        </div>
        <div class="foorRight">
            <svg class="icon" aria-hidden="true" v-if="isbtnShow">
                <use xlink:href="#icon-bofang_o" @click="play"></use>
            </svg>
            <svg class="icon" aria-hidden="true" v-if="!isbtnShow">
                <use xlink:href="#icon-caozuo-bofang-zanting" @click="play"></use>
            </svg>
            <svg class="icon" aria-hidden="true">
                <use xlink:href="#icon-zu"></use>
            </svg>
        </div>
        <audio ref="radio" :src="`https://music.163.com/song/media/outer/url?id=${playList[playListIndex].id}.mp3`"></audio>
    </div>
</template>

<script>
import { mapState, mapMutations } from "vuex";
export default {
   name:'FootMusic',
   data() {
       return {
       }
   },
   computed:{
       ...mapState({
      playList: state => state.Music.playList,
      playListIndex: state => state.Music.playListIndex,
      isbtnShow: state => state.Music.isbtnShow,
    }),
   },
   mounted() {
       console.log(this.$refs);
   },
   methods: {
       play(){
        //  判断音乐状态
           if(this.$refs.radio.paused){
               this.$refs.radio.play()
               this.updateIsbtnShow(false)
           }else{
               this.$refs.radio.pause()
               this.updateIsbtnShow(true)
           }
       },
       ...mapMutations(
           ['updateIsbtnShow']
       )
   },
   watch:{
       playListIndex:function() { // 点击列表更改index后自动播放
           this.$refs.radio.autoplay = true
           if(this.$refs.radio.paused){
               this.updateIsbtnShow(false)
           }
       }
   }
}
</script>

<style lang='less'>
    .FooterMusic{
        width: 100%;
        height: 1.2rem;
        background-color: #fff;
        position: fixed;
        bottom: 0;
        border-top: 1px solid black;
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: .2rem;
        .footLeft{
            width: 70%;
            height: 1.2rem;
            display: flex;
            justify-content: flex-start;
            align-items: center;
            
            img{
                width: .8rem;
                height: .8rem;
                border-radius: .8rem;
            }
            .songDetail{
                margin-left: .1rem;
                p{
                    font-weight: 700;
                }
                span{
                    opacity: 0.7;
                    font-size: .24rem;
                }
            }
        }
        .foorRight{
            width: 30%;
            height: 1.2rem;
            line-height: 1.2rem;
            display: flex;
            justify-content: flex-end;
            align-items: center;
            .icon{
                margin-right: .2rem;
                width: .8rem;
                height: .8rem;
            }
        }
    }
</style>
